<!DOCTYPE html>
<html lang="en" class="no-js" xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
	layout:decorator="layout">
<head>

<title>sku添加</title>
<style>
</style>
</head>
<body>
	<div layout:fragment="content">
		<form role="form" th:action="@{/goods/goods/saveSKU}"
			id="goods_sku_check" name="theForm" th:object="${goods}"
			method="post" class="form-horizontal">
			<input type="hidden" name="id" th:value="${goods.id}" />
			<table
				class="table table-striped table-hover table-bordered form-group"
				id="sku_from_check">
				<thead>
					<tr>
						<th th:if="${attrOne} !=null" th:text="${attrOne}"></th>
						<th th:if="${attrTwo} !=null" th:text="${attrTwo}"></th>
						<th style="text-align: center;">货品号<span style='color: red;'
							aria-required='true'>* </span></th>
						<th style="text-align: center;">价格<span style='color: red;'
							aria-required='true'>* </span></th>
						<th style="text-align: center;">库存<span style='color: red;'
							aria-required='true'>* </span></th>
						<th style="text-align: center;">条形码</th>
					</tr>
				</thead>
				<tbody>
					<tr th:each="data : ${goods.SKUList}">


						<td th:text="${data.goodsAttributeName}"></td>


						<td th:if="${attrTwo} !=null"
							th:text="${data.goodsAttributeValues}"></td>



						<td class="form-group" id="goodsSN_td"><input
							style="text-align: center; ime-mode: disabled;" type="text"
							class="form-control" required='required' placeholder="货品号"
							th:name="|SKUList[${dataStat.index}].sku_goodsSN|"
							th:value="|${data.sku_goodsSN}|" maxlength="100"
							alt="sku_goodsSn"
							th:attr="id='skuGoodsSN'+${dataStat.index},onchange='checkSkuSN(this,'+${dataStat.index}+')'" />
							<input type="hidden" th:value="|${data.sku_goodsSN}|" th:attr="id='skuGoodsSNHidden'+${dataStat.index}" />
						</td>


						<td class="form-group"><input style="text-align: center;"
							type="text" class="form-control" required='required'
							number="true" placeholder="价格"
							th:name="|SKUList[${dataStat.index}].goodsPrice|"
							th:value="|${data.goodsPrice}|" alt="goodsPrice"
							th:attr="id='skuPrcie'+${dataStat.index},onchange='checkPrice(this,'+${dataStat.index}+');'" />
						</td>

						<td class="form-group"><input style="text-align: center;"
							type="text" class="form-control" required='required'
							placeholder="库存" th:name="|SKUList[${dataStat.index}].goodsNum|"
							th:value="|${data.goodsNum}|" MaxLength='5' alt="goodsNum"
							th:attr="id='skuGoodsNum'+${dataStat.index},onchange='checkGoodsNum(this,'+${dataStat.index}+');'" />
						</td>

						<td><input style="text-align: center;" type="text"
							class="form-control" placeholder="条形码"
							th:name="|SKUList[${dataStat.index}].shapeCode|"
							th:value="|${data.shapeCode}|" MaxLength='10' /></td>

						<td style="display: none;"><input style="text-align: center;"
							type="hidden" class="form-control"
							th:name="|SKUList[${dataStat.index}].id|" th:value="${data.id}" />
							<input style="text-align: center;" type="hidden"
							th:name="|SKUList[${dataStat.index}].goodsAttributeName|"
							th:value="|${data.goodsAttributeName}|" /> <input
							th:if="${attrTwo} !=null" style="text-align: center;"
							type="hidden"
							th:name="|SKUList[${dataStat.index}].goodsAttributeValues|"
							th:value="|${data.goodsAttributeValues}|" /></td>

					</tr>
				</tbody>


			</table>
			<div class="form-actions fluid">
				<div class="col-md-offset-3 col-md-9">
					<button type="submit" class="btn blue" id="bt_submit"
						name="button_submit" onclick="closeWin();">提交</button>
				</div>
			</div>
		</form>

	</div>

</body>
</html>


<script th:inline="javascript">
	/*<![CDATA[*/
	var MSG_UNLOAD = "内容没有保存，是否确认关闭窗口！";
	var UnloadConfirm = {};
	UnloadConfirm.set = function(confirm_msg) {
		window.onbeforeunload = function(event) {
			event = event || window.event;
			event.returnValue = confirm_msg;
		}
	}
	UnloadConfirm.clear = function() {
		window.onbeforeunload = function() {
		};
	}
	function closeWin() {
		UnloadConfirm.clear();
	}

	function initPage() {
		UnloadConfirm.set(MSG_UNLOAD);

	}
	initPage();

	$(document).keydown(function(event) {
		if ((event.altKey) && ((event.keyCode == 37) || //屏蔽 Alt+ 方向键 ← 
		(event.keyCode == 39))) //屏蔽 Alt+ 方向键 → 
		{
			event.returnValue = false;
			return false;
		}
		/* if(event.keyCode==8){
			return false; //屏蔽退格删除键  
		} */
		if (event.keyCode == 116) {
			return false; //屏蔽F5刷新键 
		}
		if ((event.ctrlKey) && (event.keyCode == 82)) {
			return false; //屏蔽alt+R 
		}
	});

	function checkSkuSN(e, index) {
		var currentVal = e.value;
		/* if(currentVal == ""){
			alert("货品号不能为空！");
			$("#skuGoodsSN" + index).attr("value",$("#skuGoodsSNHidden" + index).val());
		} */
		var currentTd = $(e).parent();
		var indexCol = $("#sku_from_check th:contains('货品号')").index();
		var nth_index = indexCol + 1;
		var $all_Sn = $("#sku_from_check tr td:nth-child(" + nth_index
				+ "):not(:eq(" + index + "))");

		$all_Sn.each(function() {
			if ($(this).children('input')[0].value == currentVal) {
				alert("货品号已存在！");
				$("#skuGoodsSN" + index).attr("value", "");
			}
		});

		$.ajax({
			url : '/goods/goods/verifySKuGoodsSN',
			data : {
				skuGoodsSN : e.value
			},
			method : 'post',
			success : function(data) {
				if (data == false) {
					alert("货品号已存在！");
					$("#skuGoodsSN" + index).attr("value", "");
				}
			}
		});
	}

	function checkPrice(num, index) {
		var reNum = /^(0|[1-9][0-9]*)$|^[0-9]+(.[0-9]{1,2})?$/;
		if (reNum.test(num.value)) {
			if (num.value > 99999999.99) {
				alert('价格最大值为99999999.99且必须为数字');
				$("#skuPrcie" + index).attr("value", "");
			} else {
				return true;
			}
		} else {
			if (num.value < 0) {
				alert("价格不能为负数！");
			} else {
				alert("价格填写不正确，应该保留小数点后两位！");
			}
			$("#skuPrcie" + index).attr("value", "");
		}
	}

	function checkGoodsNum(num, index) {
		var reNum = /^[0-9]*[0-9][0-9]*$/;
		if (reNum.test(num.value)) {
			if (num.value > 60000) {
				alert("库存数量不能超过6万");
				$("#skuGoodsNum" + index).attr("value", "");
			} else {
				return false;
			}
		} else {
			if (num.value < 0) {
				alert("库存不能为负数！");
			} else {
				alert("库存填写不正确，应该为正整数！");
			}
			$("#skuGoodsNum" + index).attr("value", "");
		}
	}
	function upFrom() {
		$("#goods_sku_check").submit();
	}
	function upFromAndEdit() {
		$("#goodsMark").attr("value", "2");
		$("#goods_sku_check").submit();
	}

	/*]]>*/
</script>